package view.employee;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.catalina.Session;

import dal.employee.Employee;
import dal.employee.EmployeeUtil;

/**
 * Servlet implementation class SubmitDB
 */
@WebServlet("/ViewEmployee")
public class ViewEmployee extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ViewEmployee() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		EmployeeUtil employeeUtil = new EmployeeUtil();
		System.out.println("Redirect");
		ArrayList<Object> al = employeeUtil.get();
		System.out.println("size = " + al.size());

		HttpSession session = request.getSession();
		session.setAttribute("al", al);

		/*
		 * RequestDispatcher
		 * requestDispatcher=request.getRequestDispatcher("ViewEmployee.jsp");
		 * requestDispatcher.forward(request, response);
		 */

		request.getRequestDispatcher("EmployeeView.jsp").forward(request,
				response);

		/*
		 * for (Object ob : al) { Employee e = (Employee) ob;
		 * System.out.println(e.getEmployeeId() + " " + e.getName()); }
		 */

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		EmployeeUtil employeeUtil = new EmployeeUtil();
		System.out.println("Redirect");
		ArrayList<Object> al = employeeUtil.get();
		System.out.println("size = " + al.size());

		HttpSession session = request.getSession();
		session.setAttribute("al", al);

		/*
		 * RequestDispatcher
		 * requestDispatcher=request.getRequestDispatcher("ViewEmployee.jsp");
		 * requestDispatcher.forward(request, response);
		 */

		request.getRequestDispatcher("ViewEmployee.jsp").forward(request,
				response);

		/*
		 * for (Object ob : al) { Employee e = (Employee) ob;
		 * System.out.println(e.getEmployeeId() + " " + e.getName()); }
		 */

	}

}
